********************************************************************************
*																		       *
* 							VAP								 				   *
*								     									       *
********************************************************************************

* -----> This do-file: All tables and graphs 

********************************************************************************

set more off
clear all
set matsize 3000
set maxvar 10000

************************************


* Path 
if "`c(username)'"=="Juan S. Morales" | "`c(username)'"=="jmorales" {
	global PathData = "C:/Users/`c(username)'/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Data/"
	global PathFig = "C:/Users/`c(username)'/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Figures/"
	global PathTab = "C:/Users/`c(username)'/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Tables/"
	}
else { 
	global PathData = "/Users/JNG/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Data/"
	global PathFig = "/Users/JNG/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Figures/"
	global PathTab = "/Users/JNG/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Tables/"
	} 

use "${PathData}API2_polandstata.dta", clear


gen date = substr(created_at,1,10)
gen month = substr(date,6,2)
gen year = substr(date,1,4)
gen day = substr(date,9,2)
gen hour = substr(created_at,12,2)
destring(month), replace
destring(year), replace
destring(day), replace
destring(hour), replace
gen time = (year-2012)*12 + month
gen timeD = (year-2012)*365 + (month==2)*31 + (month==3)*(31+28) + (month==4)*(31*2 + 28) + (month==5)*(31*2 + 28 +30) + (month==6)*(31*3 + 28 +30) + (month==7)*(31*3 + 28 + 30*2) + (month==8)*(31*4 + 28 + 30*2) + (month==9)*(31*5 + 28 + 30*2) + (month==10)*(31*5 + 28 + 30*3) + (month==11)*(31*6 + 28 + 30*3) + (month==12)*(31*6 + 28 + 30*4) + day + 1*((month>2 & year==2012)|(year>2012))
gen week = round(timeD/7)
gen date2 = mdy(month, day, year)

gen gg_rt = strpos(text, "rt ") == 1

gen log_rt = log(rt_count + 1)
gen log_fav = log(favcount + 1)
gen log_engagement = log(rt_count + favcount + 1)
egen userid = group(screen_name)
bysort date2 userid: gen N_du = _N


gen dayC_ada = date2 - 21562
gen dayC_sq_ada = dayC_ada*dayC_ada
gen dayC_cu_ada = dayC_ada*dayC_ada*dayC_ada
gen post_ada = date2>=21562
gen dayC_post_ada = dayC_ada*post_ada
gen dayC_sq_post_ada = dayC_sq_ada*post_ada
gen dayC_cu_post_ada = dayC_cu_ada*post_ada

gen hour_sq = hour*hour
gen hour_cu = hour*hour*hour

bysort userid: gen n_u = _n
gen ffd_dayssinceE_ada = 99999
gen ffd_targetdate_ada = 21562
foreach targetdate in 21562 {
	replace ffd_dayssinceE_ada = (date2-`targetdate') if (abs(date2-`targetdate')<=abs(ffd_dayssinceE_ada))
	replace ffd_targetdate_ada = `targetdate' if (abs(date2-`targetdate')<=abs(ffd_dayssinceE_ada))
}
gen event_days_ada = date2-21562

gen timeWindow0_ada = ffd_dayssinceE_ada>-3 & ffd_dayssinceE_ada<2
gen timeWindow1_ada = ffd_dayssinceE_ada>-6 & ffd_dayssinceE_ada<5
gen timeWindow2_ada = ffd_dayssinceE_ada>-11 & ffd_dayssinceE_ada<10
gen timeWindow3_ada = ffd_dayssinceE_ada>-16 & ffd_dayssinceE_ada<15
gen timeWindow4_ada = ffd_dayssinceE_ada>-21 & ffd_dayssinceE_ada<20
gen timeWindow5_ada = ffd_dayssinceE_ada>-31 & ffd_dayssinceE_ada<30


gen gg_hashtag = strpos(text, "#")>0
gen gg_at = strpos(text, "@")>0
gen gg_http = strpos(text, "http")>0

gen text_l = lower(text)
replace text = text_l
drop text_l
replace text = subinstr(text, "á", "a",.) 
replace text = subinstr(text, "é", "e",.) 
replace text = subinstr(text, "í", "i",.) 
replace text = subinstr(text, "ó", "o",.) 
replace text = subinstr(text, "ú", "u",.)
replace text = subinstr(text, "ñ", "nh",.)
replace text = subinstr(text, ",", " ",.)
replace text = subinstr(text, `"""',  "", .)
replace text = subinstr(text, ".", " ",.) 
replace text = subinstr(text, "-", " ",.)
replace text = subinstr(text, "!", " ",.) 
replace text = subinstr(text, "/", " ",.)
replace text = subinstr(text, "…", " ",.)
replace text = subinstr(text, ":", " ",.)
replace text = subinstr(text, ";", " ",.)
replace text = subinstr(text, "#", "",.)
replace text = subinstr(text, "@", "",.)
forvalues i = 1(1)7 {
	replace text = subinstr(text, "  ", " ",.)
}

replace text = " " + text
gen threat =  strpos(text, "nienawi") + strpos(text, "wrogo") + strpos(text, "pogard") + strpos(text, " odraza") + strpos(text, "obrzydzenie") + strpos(text, "agresja") + strpos(text, "hejt")  + strpos(text, "grozi")  + strpos(text, "grob")  + strpos(text, "zagroen")  + strpos(text, "niebezpieczestw")  >0
gen unity =  strpos(text, "jedno ") + strpos(text, "jednoi") + strpos(text, "solidarno") + strpos(text, "porozumienie") + strpos(text, "pojedna") + strpos(text, "blisko ") + strpos(text, "bliskoi") >0
gen criticism =  strpos(text, "krytyczn") + strpos(text, "wadliw") + strpos(text, "nieodpowiedzi") + strpos(text, "oszustw") + strpos(text, "kamstw") + strpos(text, "nielegal") + strpos(text, "nieuczciw") + strpos(text, "niemoraln") + strpos(text, " mylc") + strpos(text, " bedn")  >0

gen post_threat = post_ada * threat
gen post_unity = post_ada * unity
gen post_criticism = post_ada * criticism

label variable post_criticism "Post x Explicit criticism"
label variable post_unity "Post x Call for unity"
label variable post_threat "Post x Threat"

gen gg_adamowicz = strpos(text, "adamowicz")>0

replace text = " " + text
gen opMentions = strpos(text," rzd") + strpos(text," min ") + strpos(text,"minist") + strpos(text,"wicemin") + strpos(text,"pis ") + strpos(text,"tvp") + strpos(text,"andruszkiewicz") + strpos(text,"berni_krynick") + strpos(text,"budet") + strpos(text,"premier") + strpos(text,"morawieck") + strpos(text,"pisowsk") + strpos(text,"macierewicz") + strpos(text,"kaczysk") + strpos(text," msz ") + strpos(text,"tygodnik_sieci") + strpos(text,"smolesk") + strpos(text,"misiewicz") + strpos(text,"tasmykaczynsk") + strpos(text,"glapiski") + strpos(text,"glapinski") + strpos(text,"szydo") + strpos(text,"ziobro") + strpos(text,"zieliski") + strpos(text,"gowin") + strpos(text,"jbrudzinski") + strpos(text,"drelich") + strpos(text,"terlecki") + strpos(text,"sdownictw") + strpos(text,"pisorgpl") + strpos(text," nbp ") + strpos(text,"wicemarsz") + strpos(text," cba ") + strpos(text,"patryk jaki") + strpos(text,"policj") + strpos(text,"czaputowicz") + strpos(text,"gliski")
replace opMentions = opMentions>0
gen govMentions = strpos(text," opozycj") + strpos(text,"bzdrojewski") + strpos(text," lewic") + strpos(text,"olejnik") + strpos(text," lewicow") + strpos(text," biedro") + strpos(text," lewac") + strpos(text," psl_") + strpos(text," psl ") + strpos(text,"gazwyb") + strpos(text," nowick") + strpos(text," sikorsk") + strpos(text,"schetyn") + strpos(text," neuman") + strpos(text,"tomasz_lis") + strpos(text,"tomasz lis") + strpos(text," lis_tomasz") + strpos(text," tusk") + strpos(text," platform") + strpos(text,"trzaskowski_") + strpos(text,"platforma_org") + strpos(text,"klubnauer") + strpos(text," gw_") + strpos(text,"gazetawyborcza") + strpos(text,"tvn24")
replace govMentions = govMentions>0
replace govMentions = govMentions + strpos(text,"platforma_org")>0
replace govMentions = govMentions + strpos(text,"tomaszsiemoniak")>0
replace govMentions = govMentions + strpos(text,"arlukowicz")>0
replace govMentions = govMentions + strpos(text,"bbudka")>0
replace govMentions = govMentions + strpos(text,"andrzejhalicki")>0
replace govMentions = govMentions + strpos(text,"slawekneumann")>0
replace govMentions = govMentions + strpos(text,"schetynadlapo")>0
replace govMentions = govMentions + strpos(text,"mkierwinski")>0
replace govMentions = govMentions + strpos(text,"jangrabiec")>0
replace govMentions = govMentions + strpos(text,"achybicka")>0
replace govMentions = govMentions + strpos(text,"protasiewiczj")>0
replace govMentions = govMentions + strpos(text,"zpawlowicz")>0
replace govMentions = govMentions + strpos(text,"trzaskowski_")>0
replace govMentions = govMentions + strpos(text,"tomaszlenz")>0
replace govMentions = govMentions + strpos(text,"hannagw")>0
replace govMentions = govMentions + strpos(text,"asia_mucha")>0
replace govMentions = govMentions + strpos(text,"niesiolowskis")>0
replace govMentions = govMentions + strpos(text,"bbukiewicz")>0
replace govMentions = govMentions + strpos(text,"c_grabarczyk")>0
replace govMentions = govMentions + strpos(text,"ikatarasinska")>0
replace govMentions = govMentions + strpos(text,"ctomczyk")>0
replace govMentions = govMentions + strpos(text,"sowamarek")>0
replace govMentions = govMentions + strpos(text,"ireneuszras")>0
replace govMentions = govMentions + strpos(text,"kopacz_ewa")>0
replace govMentions = govMentions + strpos(text,"m_k_blonska")>0
replace govMentions = govMentions + strpos(text,"adam_korol")>0
replace govMentions = govMentions + strpos(text,"pomaska")>0
replace govMentions = govMentions + strpos(text,"henryka_henia50")>0
replace govMentions = govMentions + strpos(text,"miroslawanykiel")>0
replace govMentions = govMentions + strpos(text,"marianzembala")>0
replace govMentions = govMentions + strpos(text,"urszulaaugustyn")>0
replace govMentions = govMentions + strpos(text,"kr_szumilas")>0
replace govMentions = govMentions + strpos(text,"okladrewnowicz")>0
replace govMentions = govMentions + strpos(text,"mswitczak")>0
replace govMentions = govMentions + strpos(text,"jakubrutnicki")>0
replace govMentions = govMentions + strpos(text,"mjanyska")>0
replace govMentions = govMentions + strpos(text,"ziolkowskiszym")>0
replace govMentions = govMentions + strpos(text,"waldydzikowski")>0
replace govMentions = govMentions + strpos(text,"slawomirnitras")>0
replace govMentions = govMentions + strpos(text,"krzysztofbrejza")>0
replace govMentions = govMentions + strpos(text,"arkadiuszmyrcha")>0
replace govMentions = govMentions + strpos(text,"mwielichowska")>0
replace govMentions = govMentions + strpos(text,"gajewska_kinga")>0
replace govMentions = govMentions + strpos(text,"newsplatforma")>0
replace govMentions = govMentions + strpos(text,"grzegorzfurgo")>0
replace govMentions = govMentions + strpos(text,"bborusewicz")>0
replace govMentions = govMentions + strpos(text,"tomaszsiemoniak")>0
replace govMentions = govMentions + strpos(text,"rtyszkiewicz")>0
replace govMentions = govMentions + strpos(text,"jaroslawduda")>0
replace govMentions = govMentions + strpos(text,"zdzislaw_gawlik")>0
replace govMentions = govMentions + strpos(text,"arturgierada")>0
replace govMentions = govMentions + strpos(text,"a_marchewka")>0
replace govMentions = govMentions + strpos(text,"jacek_protas")>0
replace govMentions = govMentions + strpos(text,"wojciechsaluga")>0
replace govMentions = govMentions + strpos(text,"wslugocki")>0
replace govMentions = govMentions + strpos(text,"hannazdanowska")>0
replace govMentions = govMentions + strpos(text,"prezydentzuk")>0
replace govMentions = govMentions + strpos(text,"izabela_debska")>0
replace govMentions = govMentions + strpos(text,"tadeuszzwiefka")>0
replace govMentions = govMentions + strpos(text,"donaldtusk")>0
replace opMentions = opMentions + strpos(text,"piotr_naimski")>0
replace opMentions = opMentions + strpos(text,"pisorgpl")>0
replace opMentions = opMentions + strpos(text,"morawieckim")>0
replace opMentions = opMentions + strpos(text,"jbrudzinski")>0
replace opMentions = opMentions + strpos(text,"patrykjaki")>0
replace opMentions = opMentions + strpos(text,"andzyberto")>0
replace opMentions = opMentions + strpos(text,"kurskipl")>0
replace opMentions = opMentions + strpos(text,"piotrglinski")>0
replace opMentions = opMentions + strpos(text,"jaroslaw_gowin")>0
replace opMentions = opMentions + strpos(text,"stkarczewski")>0
replace opMentions = opMentions + strpos(text,"marekkuchcinski")>0
replace opMentions = opMentions + strpos(text,"beataszydlo")>0
replace opMentions = opMentions + strpos(text,"beatamk")>0
replace opMentions = opMentions + strpos(text,"e_rafalska")>0
replace opMentions = opMentions + strpos(text,"krystpawlowicz")>0
replace opMentions = opMentions + strpos(text,"ziobropl")>0
replace opMentions = opMentions + strpos(text,"beatakempa_kprm")>0
replace opMentions = opMentions + strpos(text,"mblaszczak")>0
replace opMentions = opMentions + strpos(text,"macierewicz_a")>0
replace opMentions = opMentions + strpos(text,"elzbietawitek")>0
replace opMentions = opMentions + strpos(text,"_annazalewska")>0
replace opMentions = opMentions + strpos(text,"michaldworczyk")>0
replace opMentions = opMentions + strpos(text,"latostomasz")>0
replace opMentions = opMentions + strpos(text,"slawzawislak")>0
replace opMentions = opMentions + strpos(text,"wassermann_ma")>0
replace opMentions = opMentions + strpos(text,"arekmularczyk")>0
replace opMentions = opMentions + strpos(text,"w_bernacki")>0
replace opMentions = opMentions + strpos(text,"mareksuski")>0
replace opMentions = opMentions + strpos(text,"akosztowniak")>0
replace opMentions = opMentions + strpos(text,"minenergii")>0
replace opMentions = opMentions + strpos(text,"a_czartoryski")>0
replace opMentions = opMentions + strpos(text,"mariuszkaminsk")>0
replace opMentions = opMentions + strpos(text,"sasinjacek ?")>0
replace opMentions = opMentions + strpos(text,"bogdan_rzonca")>0
replace opMentions = opMentions + strpos(text,"andrzejszlachta")>0
replace opMentions = opMentions + strpos(text,"mrirw_gov_pl")>0
replace opMentions = opMentions + strpos(text,"d_piontkowski")>0
replace opMentions = opMentions + strpos(text,"mkidn_gov_pl")>0
replace opMentions = opMentions + strpos(text,"stanislaw_szwed")>0
replace opMentions = opMentions + strpos(text,"szymongizynski")>0
replace opMentions = opMentions + strpos(text,"izabelakloc")>0
replace opMentions = opMentions + strpos(text,"andrzejduda")>0
replace opMentions = opMentions + strpos(text,"annamkrupka")>0
replace opMentions = opMentions + strpos(text,"iwonaarent")>0
replace opMentions = opMentions + strpos(text,"joannalichocka")>0
replace opMentions = opMentions + strpos(text,"witoldczarneck3")>0
replace opMentions = opMentions + strpos(text,"tadeuszdziuba")>0
replace opMentions = opMentions + strpos(text,"zagorskimarek")>0
replace opMentions = opMentions + strpos(text,"marekgrobarczyk")>0
replace opMentions = opMentions + strpos(text,"amadamczyk")>0
replace opMentions = opMentions + strpos(text,"jerzykwiecinski")>0
replace opMentions = opMentions + strpos(text,"jemilewicz")>0
replace opMentions = opMentions + strpos(text,"witoldbanka")>0
replace opMentions = opMentions + strpos(text,"jczaputowicz")>0
replace opMentions = opMentions + strpos(text,"szumowskilukasz")>0
replace opMentions = opMentions + strpos(text,"j_kopcinska")>0
replace opMentions = opMentions + strpos(text,"profkarski")>0
replace opMentions = opMentions + strpos(text,"ryszardterlecki")>0
replace opMentions = opMentions + strpos(text,"r_czarnecki")>0
replace opMentions = opMentions + strpos(text,"grzegorzczelej")>0
replace opMentions = opMentions + strpos(text,"anita_cz")>0
replace opMentions = opMentions + strpos(text,"ministerjurgiel")>0
replace opMentions = opMentions + strpos(text,"cymanskitadeusz")>0
replace opMentions = opMentions + strpos(text,"jacekzalek")>0




***** TABLE A27 *****


eststo clear
eststo, title("Engagement"): reghdfe log_engagement threat post_threat criticism post_criticism unity post_unity hour_sq hour gg_hashtag gg_at gg_rt gg_http gg_adamowicz govMentions opMentions  if timeWindow3_ada & lang=="pl",  cl(userid) abs( date2)
estadd local dFE = "Yes"
estadd local pFE = "Yes"
estadd local controls = "Yes"
eststo, title("Retweets"): reghdfe log_rt threat post_threat criticism post_criticism unity post_unity hour_sq hour gg_hashtag gg_at gg_rt gg_http gg_adamowicz govMentions opMentions  if timeWindow3_ada & lang=="pl", cl(userid) abs( date2)
estadd local dFE = "Yes"
estadd local pFE = "Yes"
estadd local controls = "Yes"
eststo, title("Likes"): reghdfe log_fav threat post_threat criticism post_criticism unity post_unity hour_sq hour gg_hashtag gg_at gg_rt gg_http gg_adamowicz govMentions opMentions  if timeWindow3_ada  & lang=="pl", cl(userid) abs( date2)
estadd local dFE = "Yes"
estadd local pFE = "Yes"
estadd local controls = "Yes"
esttab using "${PathTab}TableA27.tex", b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) keep(threat post_threat criticism post_criticism unity post_unity) stats(N pFE dFE controls, fmt(0) labels("N" "Day FE" "Politician FE" "Controls")) label nodepvar mtitles title("Violent attack and Twitter engagement: Negative tweets effect (general population)") replace nonotes postfoot(" ")




